#include <linux/module.h>
 
#include <linux/kernel.h>
#include <linux/init.h>      //.init.....
#include <linux/platform_device.h>
 

static int hello_remove(struct platform_device *dev);
static int __devinit hello_probe(struct platform_device *dev);

#if 0
static struct platform_driver hello_driver = {
	.probe = hello_probe,
	.remove = hello_remove,
	.driver = {
		.name = "hello",
	},
};
#endif

static int sample_sysfs_open(struct inode *inode, struct file *file)
{
	int ret;
	printk(KERN_INFO "%s\n", __FUNCTION__);
	
	return 0;
}

static int sample_sysfs_release(struct inode *inode, struct file *file)
{
	printk(KERN_INFO "%s\n", __FUNCTION__);
	return 0;
}

static int sample_sysfs_ioctl(struct inode *inode, struct file *file,
	      unsigned int cmd, unsigned long arg)
{
	printk(KERN_INFO "%s\n", __FUNCTION__);
	return 0;
}

static struct file_operations sample_sysfs_fops = {
	.owner = THIS_MODULE,
	.open = sample_sysfs_open,
	.release = sample_sysfs_release,
	.ioctl = sample_sysfs_ioctl,
};

static struct miscdevice sample_device = {
	.minor = MISC_DYNAMIC_MINOR,
	.name = "sample_sysfs",
	.fops = &sample_sysfs_fops,
};

static struct kobject * sample_attr_kobj;  /*create kobject for sysfs IF*/

static DEVICE_ATTR(attr1, S_IWUSR|S_IWGRP,
	show_attr1, store_attr1);

static DEVICE_ATTR(attr2, S_IWUSR|S_IWGRP,
	show_attr2, store_attr2);

static struct attribute *sample_attributes[] = {
	&dev_attr_attr1.attr,
	&dev_attr_attr2.attr,
	NULL
};

static struct attribute_group sample_attribute_group = {
	.attrs = sample_attributes
};

static int hello_remove(struct platform_device *dev)
{
	return 0;
}

static int __devinit hello_probe(struct platform_device *dev)
{
	return 0;
}

static char *gBuf = NULL; 

static ssize_t show_attr1(struct device *device,
		struct device_attribute *attr,
	   	char *buf)
{
	printk("show attr1 \"%s\".\n", gBuf);
	
	return 0;
}

static ssize_t store_attr1(struct device *device,
		struct device_attribute *attr,
		const char *buf,
		size_t count)
{
	//unsigned long value;
	
	printk("write attr1 \"%s\".\n", buf);
	return 0;
}

static ssize_t show_attr2(struct kobject *kobj,
		struct kobj_attribute *attr,
	   	char *buf)
{
	printk("show attr2 \"%s\".\n", gBuf);
	
	return 0;
}

static ssize_t store_attr2(struct kobject *kobj,
		struct kobj_attribute *attr,
		const char *buf,
		size_t count)
{
	//unsigned long value;
	//printk("store attr1 count=%d.\n", count);
	//memcpy(gBuf, buf, count);
	//value = simple_strtoul(buf, NULL, 16);
	//printk("value is %d", value);
	return 0;
}

static int sample_sysfs_init(void)
{
	int err;

	printk("sample_sysfs init.\n");
	err = misc_register(&sample_sysfs_device);

    sysfs_create_group(&connector->kdev.kobj, &sample_attribute_group);

	return 0;
}	

static void sample_sysfs_exit(void)
{
	printk("sample_sysfs exit.\n");

	misc_deregister(&sample_sysfs_device);
}

module_init(sample_sysfs_init);
module_exit(sample_sysfs_exit);
MODULE_LICENSE("GPL");
